package entitys

import "rpcSrv/dbs/mysqlGORM"

type Like struct {
	ID               int    `json:"id"`
	Uid              int    `json:"uid"`               //用户ID
	TargetId         int    `json:"target_id"`         //目标ID
	TbName           string `json:"tb_name"`           //点赞数据的表名
	CreatedTimestamp int64  `json:"created_timestamp"` //创建时间
}

func (u *Like) TableName() string {
	return "likes"
}

const like_schema = `
create table if not exists likes
(
    id               int(10)     not null auto_increment unique,
    uid              int(10)     not null comment 'uid',
	target_id        int(10)     not null comment '目标ID',
    tb_name             varchar(60)     not null comment '点赞表名',
    created_timestamp       int(10)       default 0,
    primary key (id),
    index like_uid_tb_targetid (uid,tb_name,target_id) using btree,
	index like_targetid (target_id) using btree
) engine = INNODB
  default charset = utf8 comment '点赞收藏表';
`

func init() {
	db, err := mysqlGORM.GetMysqlDB()
	if err != nil {
		return
	}
	if !db.HasTable(new(Like).TableName()) {
		if err = db.Exec(like_schema).Error; err != nil {
			return
		}
	}

}
